package com.app.TCES.service;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.TCES.domain.Course;
import com.app.TCES.mapper.A_CourseMapper;

@Service
public class A_CourseService {

	Logger log = LogManager.getLogger(A_CourseService.class);

	@Autowired
	A_CourseMapper a_CourseMapper;

	// 查询所有课程信息
	public List<Course> selectCourses() {
		log.debug("A_CourseService======>查询所有课程信息");
		List<Course> list = a_CourseMapper.selectCourses();
		log.debug("A_CourseService======>返回所有课程信息");
		return list;
	}
	
	//删除课程信息
	public void deleteCourse(int courseId) {
		
		a_CourseMapper.deleteCourse(courseId);
	}
	
	//添加(验证ID是否存在)
	public String selectCourseId(int courseId) {
		log.debug("A_CourseService=====>查询Id是否存在");
		int a = a_CourseMapper.selectCourseId(courseId);
		log.debug("A_CourseService=====>返回信息");
		if(a>0) {
			return "NO";
		}else {
			return "YES";
		}
	}
	//添加(验证Name是否存在)
	public String  selectCourseName(String courseName) {
		log.debug("A_CourseService=====>查询Id是否存在");
		int a = a_CourseMapper.selectCourseName(courseName);
		log.debug("A_CourseService=====>返回信息");
		if(a>0) {
			return "NO";
		}else {
			return "YES";
		}
	}
	
	//添加
	public String insertCourse(int courseId,String courseName) {
		log.debug("添加课程信息");
		a_CourseMapper.insertCourse(courseId, courseName);
		
		return "YES";
	}
	
}
